home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / tcp_ip / gp / decode.c < prev    next >
C/C++ Source or Header  |  1991-12-29  |  21KB  |  684 lines

  1. #include "7plus.h"
  2. #include "globals.h"
  3.  
  4. /*
  5. *** If there's no extension in the filename, try, if a correctionfile
  6. *** already exists. If it does, correct. decode afterwards.
  7. ***
  8.  */
  9. int control_decode (char *name)
  10. {
  11.   int i;
  12.   char newname[MAXPATH];
  13.  
  14.   i = 0;
  15.   *_ext = EOS;
  16.  
  17.   fnsplit (name, NULL, NULL, NULL, _ext);
  18.   if (!*_ext)
  19.   {
  20.     sprintf (newname, "%s.cor", name);
  21.     if (!test_exist (newname))
  22.       i = decode_file (newname);
  23.   }
  24.   if (!i)
  25.    i= decode_file (name);
  26.  
  27.   return (i);
  28. }
  29.  
  30. /*
  31. *** decode a file. create error report, do correction.
  32. ***
  33. ***
  34.  */
  35.  
  36. int decode_file (char *name)
  37. {
  38.  
  39.   FILE     *rein, *raus, *report;
  40.   int      part, teil, parts, teile, parts0;
  41.   int      czeile, czeile2, fzeilen, zeilen, blockzeilen, blockz0;
  42.   int      lokaldefekt, defekt, rest, laenge, correct, hcorrupted;
  43.   int      corrpart, corrzeile, corrected, rebuilt, cor_ok, ignored;
  44.   uint     csequence, crc, ascbytes, ascb0;
  45.   ulong    danach[16], *dn;
  46.   long     binbytes, binb0, binb1;
  47.   char     zeile[81], *p, buf[81], dummi[20], dummi2[81], dummi3[20];
  48.   char     inpath[MAXFPATH], filename[13];
  49.   char     quellname[MAXPATH], rausname[MAXFNAME], orgname[MAXFNAME];
  50.   char     orgname2[66], zielname[13], ziel0[13], reportname[13];
  51.   register i, j, k;
  52.  
  53.   *buf = *orgname = EOS;
  54.   raus = NULL;
  55.   hcorrupted = 0;
  56.  
  57.   /* Isolate input-path and filename */
  58.   fnsplit (name, _drive, _dir, _file, _ext);
  59.   sprintf (inpath, "%s%s", _drive, _dir);
  60.   build_DOS_name (_file);
  61.   build_DOS_name (_ext);
  62.   _file[8] = _ext[3] = EOS;
  63.   sprintf (filename, "%s%s%s", _file, _ext[0]?".":"", _ext);
  64.   correct = ignored = 0;
  65.   /* If ext ist COR, then open COR-file and check for validity */
  66.   if (!strncmp (_ext, "cor", 4))
  67.   {
  68.     correct = 1;
  69.     cor_ok = 0;
  70.     if (crc_file (name, "7PLUS corr", " P00:\n", 1) == 1)
  71.       return (7);
  72.  
  73.     report = fopen (name, OPEN_READ_TEXT);
  74.  
  75.     /* Find starting line */
  76.     while ((p = my_fgets (zeile, 80, report)) != NULL)
  77.       if (!strncmp (zeile, "7PLUS corr", 10))
  78.         break;
  79.  
  80.     if (!p)
  81.     {
  82.       printf ("\007Invalid correction file.\n Break.");
  83.       return (7);
  84.     }
  85.  
  86.     /* Get filename from starting line */
  87.     binb1 = 0L;
  88.     sscanf (zeile, "7PLUS correction: %12s %ld", filename, &binb1);
  89.     /* Strip ext from filename */
  90.     if ((p = strrchr (filename, '.')) != NULL)
  91.       *p++ = EOS;
  92.     strlwr (filename);
  93.     strcpy (zielname, filename);
  94.     /* Get first number of part and line to correct */
  95.     my_fgets (dummi2, 80, report);
  96.     corrpart = get_hex (dummi2+2);
  97.     my_fgets (dummi2, 80, report);
  98.     corrzeile = get_hex (dummi2+2);
  99.   }
  100.  
  101.   /* If no ext or correction needed, generate filename */
  102.   if (!*_ext || correct)
  103.   {
  104.     sprintf (quellname, "%s%s.7pl", inpath, filename);
  105.     if ((rein = fopen (quellname, OPEN_READ_TEXT)) != NULL)
  106.     {
  107.       fclose (rein);
  108.       strcat (filename, ".7pl");
  109.     }
  110.     else
  111.       strcat (filename, ".p01");
  112.   }
  113.   sprintf (quellname, "%s%s", inpath, filename);
  114.  
  115.   /* open input file */
  116.   if ((rein = fopen (quellname, OPEN_READ_BINARY)) == NULL)
  117.   {
  118.     printf (cant, filename);
  119.     return (2);
  120.   }
  121.   /* Set I/O-buffering */
  122.   setvbuf (rein, NULL, _IOFBF, buflen);
  123.  
  124.   if (correct)
  125.     printf ("\nCorrecting...\n\n");
  126.   else
  127.     printf ("\nDecoding...\n\n");
  128.  
  129.   defekt = 0;
  130.   parts = 1;
  131.   /* Loop for number of parts. At beginning of first round, number of parts
  132.      unknown, that's why parts is set to 1 */
  133.   for (part = 1; part < parts +1; part++)
  134.   {
  135.     if (part == 256)
  136.     {
  137.       printf ("\007\nMore than 255 parts not allowed. Break.\n");
  138.       kill_dest (rein, raus, orgname);
  139.       return (8);
  140.     }
  141.     /* If we're already at part > 1, generate filename for next part. */
  142.     if (part != 1)
  143.     {
  144.       sprintf (filename, "%s.p%02x", zielname, part);
  145.       sprintf (quellname, "%s%s", inpath, filename);
  146.  
  147.       if ((rein = fopen (quellname, OPEN_READ_BINARY)) == NULL)
  148.       {
  149.         printf ("\007\n'%s': Not found. Break.\n", filename);
  150.         kill_dest (rein, raus, orgname);
  151.         return (2);
  152.       }
  153.       setvbuf (rein, NULL, _IOFBF, buflen);
  154.     }
  155.  
  156.     /* Read, until starting line is found. */
  157.     while ((p = my_fgets (zeile, 80, rein)) != NULL)
  158.       if (!strncmp (zeile, " go_7+. ", 7))
  159.         break;
  160.  
  161.     /* p == NULL? then no starting line found. File no good. */
  162.     if (!p)
  163.     {
  164.       printf ("\007'%s': 7PLUS-startline ", filename);
  165.       printf ("not found. Break.\n");
  166.       kill_dest (rein, raus, orgname);
  167.       return (3);
  168.     }
  169.  
  170.     if (!mcrc (zeile, 0))
  171.       rebuild (zeile, 1);
  172.  
  173.     /* Check if file went trough 7bit channel */
  174.     if (!strstr (zeile, "\xb0\xb1"))
  175.     {
  176.       printf ("\007\n'%s':\nBit 8 has been stripped! Can't decode.\n", filename);
  177.       printf ("Please check all settings of your terminal and tnc\n");
  178.       printf ("regarding 8 bit transfer.\n");
  179.       printf ("You will have to re-read '%s' from the mailbox\n");
  180.       printf ("after having corrected the settings.\n");
  181.       fclose (rein);
  182.       return (9);
  183.     }
  184.  
  185.     /* Get info from 7PLUS header */
  186.     if(sscanf (zeile+8, "%d %s %d %s %ld %s %s %s %s %s",
  187.             &teil, dummi, &teile, zielname,
  188.             &binbytes, dummi2, dummi3, dummi, dummi, dummi) != 10)
  189.       hcorrupted = 1;
  190.     ascbytes = get_hex (dummi2);
  191.     blockzeilen = get_hex (dummi3);
  192.     fzeilen = (int) (ascbytes / 64) -1; /* Number of lines in this file */
  193.     strlwr (zielname);                  /* Convert to lower case */
  194.  
  195.     if (strlen (dummi) == 5)
  196.       if (!mcrc(zeile, 0))
  197.         hcorrupted = 1;
  198.  
  199.     if (teil == 1 && !hcorrupted)
  200.     {
  201.       parts0  = teile;
  202.       strcpy (ziel0, zielname);
  203.       binb0   = binbytes;
  204.       ascb0   = ascbytes;
  205.       blockz0 = blockzeilen;
  206.     }
  207.  
  208.     if ((parts0 != teile || stricmp(ziel0, zielname) || binb0 != binbytes ||
  209.         blockz0 != blockzeilen) && !hcorrupted)
  210.       hcorrupted = 1;
  211.  
  212.     if (part == parts0 && !hcorrupted)
  213.     {
  214.       if (binb0 % (blockz0 *62))
  215.         ascb0 = (uint) (binb0 % (blockz0 *62));
  216.       else
  217.         ascb0 = blockz0 *62;
  218.       ascb0 = ((ascb0 +61) /62) *64;
  219.     }
  220.  
  221.     if (ascb0 != ascbytes && !hcorrupted)
  222.       hcorrupted = 1;
  223.  
  224.     if (correct && binb1)
  225.     {
  226.       if (binb1 != binbytes)
  227.       {
  228.         printf (notsame, "correction file");
  229.         kill_dest (rein, raus, orgname);
  230.         return (15);
  231.       }
  232.     }
  233.  
  234.     if (hcorrupted)
  235.     {
  236.       printf ("'%s': Header is corrupted. Can't continue", quellname);
  237.       kill_dest (rein, raus, orgname);
  238.       return(5);
  239.     }
  240.  
  241.     /* If first part, process filename, calculate how many valid binary bytes
  242.        are contained in last code line of last part. */
  243.     if (teil == 1)
  244.     {
  245.       *orgname2 = *buf = EOS;
  246.  
  247.       if (dummi[3] == '*')
  248.       {
  249.         if (correct)
  250.           strcpy (buf, zeile);
  251.         my_fgets (zeile, 80, rein);
  252.         if (!mcrc (zeile, 0))
  253.         {
  254.           printf ("\n\nExtended Filename corrupted. Using filename from header.\n\n");
  255.           strcpy (orgname2, zielname);
  256.         }
  257.         else
  258.           sscanf (zeile, "/%60[^/]", orgname2);
  259.       }
  260.  
  261.       strcpy (orgname, zielname);
  262.       strcpy (rausname, zielname);
  263.  
  264.       if (extended == '*' && *orgname2)
  265.         strncpy (orgname, orgname2, (size_t)(MAXFNAME-1));
  266.  
  267.       fnsplit (rausname, NULL, NULL, zielname, NULL);
  268.  
  269.       rest = (int) (binbytes % 62);
  270.       if (!rest)
  271.         rest = 62;
  272.       parts = teile; /* Set number of parts to decode. */
  273.     }
  274.     else
  275.       *buf = EOS;
  276.  
  277.  
  278.     /* If more than 1 part, generate filename for messages and handling. */
  279.     if (parts != 1)
  280.     {
  281.       fnsplit (zielname, NULL, NULL, filename, NULL);
  282.       strcpy (zielname, filename);
  283.       sprintf (dummi, ".p%02x", part);
  284.       strcat (filename, dummi);
  285.     }
  286.  
  287.     /* Current file does not contain expected part */
  288.     if (teil != part)
  289.     {
  290.       printf ("\007'%s': File does not contain part %03d. Break.\n", filename, part);
  291.       kill_dest (rein, raus, orgname);
  292.       return (4);
  293.     }
  294.  
  295.     /* If correcting, open temp-file, else open output file */
  296.     if (correct)
  297.     {
  298.       strcpy (rausname, tmpfil);
  299.       strcpy (orgname , rausname);
  300.       raus = fopen (orgname, OPEN_WRITE_TEXT);
  301.     }
  302.     else
  303.     {
  304.       /* If first part, check if output file already exists, else prompt for
  305.          new name. */
  306.       if (part == 1)
  307.       {
  308.         test_file (rein, orgname, 1, MAXFNAME-1);
  309.         raus = fopen (orgname, OPEN_WRITE_BINARY); /* open output file for writing */
  310.       }
  311.       else /* not first part, open output file for appending */
  312.         raus = fopen (orgname, OPEN_APPEND_BINARY);
  313.     }
  314.     setvbuf (raus, NULL, _IOFBF, buflen); /* As always, bufferize */
  315.  
  316.     /* Correcting, output acording message */
  317.     printf ("'%s': ", filename);
  318.     if (correct)
  319.     {
  320.       fprintf (raus, "%s%s", buf, zeile);
  321.       printf ("Correcting.\r");
  322.     }
  323.     else /* Decoding */
  324.     {
  325.       if (!defekt)
  326.         printf ("Decoding"); /* No errors detected, yet */
  327.       else
  328.         printf ("Testing");
  329.  
  330.       if (parts != 1)
  331.         printf (" part %03d of %03d", teil, parts);
  332.  
  333.         printf (".   \r");
  334.     }
  335.     
  336.     /* This is nessesary on some systems, that bufferize output to the
  337.        screen. */
  338.     fflush (stdout);
  339.     
  340.     czeile2 = -1;
  341.     lokaldefekt = zeilen = corrected = rebuilt = 0;
  342.  
  343.     /* Now decode/correct this part */
  344.     do
  345.     {
  346.       /* Get a line from code file */
  347.       p = my_fgets (zeile, 80, rein);
  348.  
  349.       /* If line starts with a space, check if it's the last line */
  350.       if (*zeile == ' ')
  351.         if (!strncmp (zeile, " stop_7+.", 8))
  352.           p = NULL; /* Last line, set end indicator */
  353.  
  354.       if (p)
  355.       {
  356.         /* Calculate CRC */
  357.         csequence = 0;
  358.         for (i=0; i<64; i++)
  359.           csequence = crctab[csequence>>8] ^ (((csequence&255)<<8) | (byte)p[i]);
  360.         csequence &= 0x3fff; /* strip calculated CRC to 14 bits */
  361.  
  362.         /* Get crc from code line */
  363.         crc_n_lnum (&crc, &czeile, p);
  364.  
  365.         if (csequence != crc)
  366.         {
  367.           if (!rebuild (p, 0))
  368.           {
  369.             ignored++; /* Incorrect CRC. Ignore line. */
  370.             continue;
  371.           }
  372.           rebuilt++;
  373.           crc_n_lnum (&crc, &czeile, p);
  374.         }
  375.  
  376.         /* Re-arrange data-charaters to 2*8 longs containing 31 bits each.*/
  377.         for (i=k=0; i<64; i++)
  378.         {
  379.           if ((i&3) == 3)
  380.           {
  381.             danach[k] = 0L;
  382.             for (j=i;j>(i-4);j--)
  383.               danach[k] = danach[k] * 216L + decode[(byte)p[j]];
  384.             k++;
  385.           }
  386.         }
  387.  
  388.         /* Number of valid binary bytes in this line. If it's the last line
  389.            of the last part, set it to the number precalculated earlier */
  390.         laenge = 62;
  391.         if (czeile == fzeilen && part == parts)
  392.           laenge = rest;
  393.       }
  394.  
  395.       /* If file ends prematurely, set current line number to number of
  396.          lines in this part, so that the missing lines can be protocolled. */
  397.       if (!p && fzeilen != czeile)
  398.         czeile = fzeilen+1;
  399.  
  400.       /* If current line number is greater than previous one -> ok */
  401.       if (czeile > czeile2)
  402.       {
  403.         /* Difference is greater than 1, then line(s) must be missing. */
  404.         if (czeile2 != czeile-1)
  405.         {
  406.           /* Are we currently correcting? */
  407.           if (!correct)
  408.           {              /* No, we're not */
  409.             /* Open file for error report, if this is the first detected error. */
  410.             if (!defekt)
  411.             {
  412.               sprintf (reportname, "%s.err", zielname);
  413.               if ((report = fopen (reportname, OPEN_WRITE_TEXT)) == NULL)
  414.               {
  415.                 printf ("\007Error while writing error report. Break.\n");
  416.                 fclose (rein);
  417.                 return (1);
  418.               }
  419.               strcpy (dummi2, reportname);
  420.               strupr (dummi2);
  421.               fprintf (report, " go_text. %s%s", dummi2, delimit);
  422.               strcpy (dummi2, rausname);
  423.               strupr (dummi2);
  424.               fprintf (report, "7PLUS error report: %s %03X",
  425.                                                    dummi2, blockzeilen);
  426.               if (*orgname2)
  427.                 fprintf (report, " /%s/", orgname2);
  428.               fprintf (report, " %ld", binbytes);
  429.               fprintf (report, delimit);
  430.             }
  431.             /* If first error in current part, output number of part */
  432.             if (!lokaldefekt)
  433.               fprintf (report, "%02X%s", part, delimit);
  434.             lokaldefekt = defekt = 1;
  435.           }
  436.           /* Loop for number of missing or corrupted lines */
  437.           for (i = czeile2+1; i < czeile; i++)
  438.           {
  439.             zeilen++; /* Number of missing or corrupted lines. */
  440.  
  441.             if (!correct)
  442.             {
  443.               /* Write number of missing line to error report */
  444.               printf (miss, i);
  445.               fprintf (report, "%03X ", i);
  446.               /* Insert line separator, if line full */
  447.               if (!(zeilen % 18) && zeilen)
  448.                 fprintf (report, delimit);
  449.             }
  450.             else
  451.             {
  452.               /* Synchronize correction file with current position in code
  453.                  file, because code file does not necessarily contain as
  454.                  many errors as covered by correction file */
  455.               while ((corrzeile < i && corrpart == part) || corrpart < part)
  456.               {
  457.                 if (!corrpart)
  458.                   break;
  459.                 my_fgets (buf, 80, report);
  460.                 my_fgets (dummi2, 80, report);
  461.                 corrzeile = get_hex (dummi2+2);
  462.                 if (dummi2[1] == 'P')
  463.                 {
  464.                   corrpart = corrzeile;
  465.                   if (corrpart)
  466.                   {
  467.                     my_fgets (dummi2, 80, report);
  468.                     corrzeile = get_hex (dummi2+2);
  469.                   }
  470.                   else
  471.                     break;
  472.                 }
  473.               }
  474.               /* If error not covered by correction file, tell about it. */
  475.               if (corrzeile > i || corrpart != part)
  476.               {
  477.                 printf (miss, i);
  478.                 fprintf (raus, "Line %03d missing\n", i);
  479.               }
  480.  
  481.               /* Error is covered in corretion file. Replace corrupted line
  482.                  with line from correction file */
  483.               if (corrzeile == i && corrpart == part)
  484.               {
  485.                 int x;
  486.                 my_fgets (buf, 80, report);
  487.                 csequence = 0;
  488.                 for (j=0; j<64; j++)
  489.                   csequence = crctab[csequence>>8] ^ (((csequence&255)<<8) | (byte)buf[j]);
  490.                 csequence &= 0x3fff;
  491.                 crc_n_lnum (&crc, &x, buf);
  492.                 if (csequence == crc && x == i)
  493.                 {
  494.                   corrected++; /* Number of corrected lines */
  495.                   printf ("\n\t\tLine %d replaced.", i);
  496.                   fprintf (raus, "%s", buf);
  497.                 }
  498.                 else
  499.                 {
  500.                   if (rebuild (buf, 0))
  501.                   {
  502.                     corrected++; /* Number of corrected lines */
  503.                     printf ("\n\t\tLine %d replaced.", i);
  504.                     fprintf (raus, "%s", buf);
  505.                   }
  506.                   else
  507.                     fprintf (raus, "%s", zeile);
  508.                 }
  509.                 /* Get next info from correction file */
  510.                 my_fgets (dummi2, 80, report);
  511.                 corrzeile = get_hex (dummi2+2);
  512.                 if (dummi2[1] == 'P')
  513.                 {
  514.                   corrpart = corrzeile;
  515.                   if (corrpart)
  516.                   {
  517.                     my_fgets (dummi2, 80, report);
  518.                     corrzeile = get_hex (dummi2+2);
  519.                   }
  520.                 }
  521.               }
  522.             }
  523.           }
  524.           /* Write previously memorized line. */
  525.           if (correct && p)
  526.             fprintf (raus, "%s", zeile);
  527.         }
  528.         else /* Line is OK */
  529.         {
  530.           /* Only write to output file, if not currently correcting and no
  531.              error detected */
  532.           if (!correct)
  533.           {
  534.             if (!lokaldefekt)
  535.             {
  536.               /* split up longs into 2 * 31 binary bytes and write. */
  537.               dn = danach;
  538.               for (i=0; i<2; i++, dn+=8)
  539.               {
  540.                 /* Re-arrange to 2*8 longs containing 32 bits. 7th and 15th long
  541.                    only contain 24 valid bits. */
  542.                 dn[0] = (dn[0] << 1) | (dn[1] >> 30);
  543.                 dn[1] = (dn[1] << 2) | (dn[2] >> 29);
  544.                 dn[2] = (dn[2] << 3) | (dn[3] >> 28);
  545.                 dn[3] = (dn[3] << 4) | (dn[4] >> 27);
  546.                 dn[4] = (dn[4] << 5) | (dn[5] >> 26);
  547.                 dn[5] = (dn[5] << 6) | (dn[6] >> 25);
  548.                 dn[6] = (dn[6] << 7) | (dn[7] >> 24);
  549.                 dn[7] = (dn[7] << 8);
  550.                 for(j=0; j<8; j++)
  551.                 {
  552.                   for (k=24;k;k-=8)
  553.                   {
  554.                     if (!laenge)
  555.                       break;
  556.                     laenge--;
  557.                     my_putc ((int) (dn[j] >> k), raus);
  558.                   }
  559.                   if (j == 7 || !laenge)
  560.                     break;
  561.                   laenge--;
  562.                   my_putc ((int) dn[j], raus);
  563.                 }
  564.               }
  565.             }
  566.           }
  567.           else /* Write previously memorized line, if correcting */
  568.             fprintf (raus, "%s", zeile);
  569.         }
  570.         czeile2 = czeile; /* Memorize current line number */
  571.       }
  572.     }
  573.     while (p); /* Loop until current code file ends */
  574.  
  575.     /* Were there missing/corrupted lines in this part? */
  576.     if (zeilen)
  577.     {
  578.       /* Yes, write FFF to error report to indicate end of this part, tell
  579.          about it */
  580.       if (!correct)
  581.         fprintf (report, "%03X%s", 0xfff, delimit);
  582.       printf ("\n\t\tMissing/corrupted lines: %d\n", zeilen);
  583.     }
  584.     else
  585.       if (rebuilt)
  586.         printf ("\n");
  587.  
  588.     if (correct)
  589.     {
  590.       /* Replace end line */
  591.       strcpy (dummi2, filename);
  592.       strupr (dummi2);
  593.       fprintf (raus, " stop_7+. (%s)\n", dummi2);
  594.       /* Tell user about success */
  595.       if (corrected)
  596.         printf ("\t\tCorrected lines: %d\n", corrected);
  597.       if (zeilen)
  598.       {
  599.         cor_ok += (zeilen - corrected);
  600.         printf ("\n'%s': Correction", filename);
  601.         if (corrected < zeilen)
  602.           printf (" not");
  603.         printf (" successful.\n\n");
  604.       }
  605.       if (part == parts)
  606.       {
  607.         if (!zeilen)
  608.           printf ("\n\n");
  609.         if (!cor_ok)
  610.           printf ("No missing lines.\n");
  611.         else
  612.         {
  613.           printf ("%d lines are still missing!\nRun 7PLUS again to create", cor_ok);
  614.           printf (" a new error report.\n");
  615.         }
  616.       }
  617.     }
  618.  
  619.     if (!lokaldefekt && defekt && parts == part && !rebuilt)
  620.       puts (spaces);
  621.  
  622.     if ((zeilen || rebuilt) && !correct)
  623.       printf ("\n");
  624.  
  625.     fclose (rein);
  626.     fclose (raus);
  627.  
  628.     if (correct)
  629.     {
  630.       /* Erase code file and rename tempfile to code file's name */
  631.       if (corrected || ignored)
  632.       {
  633.         unlink (quellname);
  634.         rename (tmpfil, quellname);
  635.       }
  636.       else /* If no correction made and no errors detected, get rid of tempfile */
  637.         unlink (tmpfil);
  638.  
  639.       if (cor_ok && part == parts)
  640.         return (16);
  641.     }
  642.   }
  643.  
  644.   if (!correct)
  645.   {
  646.     if (defekt) /* Put end line into error report */
  647.     {
  648.       fprintf (report, "00%s", delimit);
  649.       fclose (report);
  650.       crc_file (reportname, "7P", "00\n", 0);
  651.       report = fopen (reportname, OPEN_APPEND_TEXT);
  652.       fprintf (report, " stop_text.%s", delimit);
  653.       if (endstr)
  654.         fprintf (report, "%s%s", endstr, delimit);
  655.       fclose (report);
  656.     }
  657.     else
  658.     {
  659.       rein = fopen (orgname, OPEN_READ_TEXT);
  660.       fseek (rein, 0L, SEEK_END); /* position read pointer to end of file. */
  661.       binb0 = ftell (rein);       /* get size. */
  662.       fseek (rein, 0L, SEEK_SET); /* reposition to beginning of file. */
  663.       fclose (rein);
  664.       if (binb0 == binbytes)
  665.       {
  666.         printf ("\n\nDecoding successful! '%s', %ld bytes.\n\n", orgname, binbytes);
  667.         return (0);
  668.       }
  669.     }
  670.  
  671.     printf ("\n\nDecoding of '%s' not successful.\n\n", orgname);
  672.     if (binb0 != binbytes)
  673.       printf ("Reason unknown......\n");
  674.     else
  675.     {
  676.       printf ("Send error report '%s' to originator of '%s'\nfor correction.\n",
  677.               reportname, orgname);
  678.     }
  679.     unlink (orgname);
  680.     return (11);
  681.   }
  682.   return (0);
  683. }
  684.